<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/19 0019
 * Time: 下午 3:08
 */
namespace app\article\model;
use think\console\command\make\Model;
use think\Db;

class Likes extends Model{
    public function like_add($data){
        $like = Db::name('likes')
            ->where(['type_id'=>$data['type_id'],'user_id'=>$data['user_id']])
            ->find();
        if ($like){
            if ($like['status']===1){
                $update = Db::name('likes')->where(['id'=>$like['id']])->update(['status'=>0]);
            }else{
                $update = Db::name('likes')->where(['id'=>$like['id']])->update(['status'=>1]);
            }
            return $update;
        }
        $add = Db::name('likes')->insertGetId($data);
        return $add;
    }
}